package com.ruoyi.project.gxgw_modules.lost.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.gxgw_modules.lost.domain.Lost;
import com.ruoyi.project.gxgw_modules.lost.service.ILostService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 寻宠启示记录 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-01-22
 */
@Controller
@RequestMapping("/gxgw_modules/lost")
public class LostController extends BaseController
{
    private String prefix = "gxgw_modules/lost";
	
	@Autowired
	private ILostService lostService;
	
	@RequiresPermissions("gxgw_modules:lost:view")
	@GetMapping()
	public String lost()
	{
	    return prefix + "/lost";
	}
	
	/**
	 * 查询寻宠启示记录列表
	 */
	@RequiresPermissions("gxgw_modules:lost:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Lost lost)
	{
		startPage();
        List<Lost> list = lostService.selectLostList(lost);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出寻宠启示记录列表
	 */
	@RequiresPermissions("gxgw_modules:lost:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Lost lost)
    {
    	List<Lost> list = lostService.selectLostList(lost);
        ExcelUtil<Lost> util = new ExcelUtil<Lost>(Lost.class);
        return util.exportExcel(list, "lost");
    }
	
	/**
	 * 新增寻宠启示记录
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存寻宠启示记录
	 */
	@RequiresPermissions("gxgw_modules:lost:add")
	@Log(title = "寻宠启示记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Lost lost)
	{		
		return toAjax(lostService.insertLost(lost));
	}

	/**
	 * 修改寻宠启示记录
	 */
	@GetMapping("/edit/{lostId}")
	public String edit(@PathVariable("lostId") Integer lostId, ModelMap mmap)
	{
		Lost lost = lostService.selectLostById(lostId);
		mmap.put("lost", lost);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存寻宠启示记录
	 */
	@RequiresPermissions("gxgw_modules:lost:edit")
	@Log(title = "寻宠启示记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Lost lost)
	{		
		return toAjax(lostService.updateLost(lost));
	}
	
	/**
	 * 删除寻宠启示记录
	 */
	@RequiresPermissions("gxgw_modules:lost:remove")
	@Log(title = "寻宠启示记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(lostService.deleteLostByIds(ids));
	}
	
}
